// 当 push 的元素小于等于辅助栈栈顶时，存入辅助站即可，这样辅助站栈顶永远是我们的最小元素。pop 需要考虑当原栈顶跟辅助栈顶相同的情况。
var MinStack = function() {
    this.stack = []; // 原栈 将元素存入
    this.min_stack = [Infinity];    // 辅助栈 存入最小元素
};
/**
 * @param {number} val
 * @return {void}
 */
MinStack.prototype.push = function (val) {
    this.stack.push(val);    // push 元素到栈顶
    this.min_stack.push(Math.min(val, this.min_stack[this.min_stack.length-1]));//  push the minimum value
};
/**
 * @return {void}
 */
MinStack.prototype.pop = function() {
    this.stack.pop();
    this.min_stack.pop();
};
/**
 * @return {number}
 */
MinStack.prototype.top = function() {
    return this.stack[this.stack.length-1];
};
/**
 * @return {number}
 */
MinStack.prototype.getMin = function () {
    const max = Infinity;
    return this.min_stack[this.min_stack.length - 1];
};
/**
 * Your MinStack object will be instantiated and called as such:
 * var obj = new MinStack()
 * obj.push(val)
 * obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.getMin()
 */